Skip to content

[Cherry-Pick][OP]Unify MoE op with moe_permute path for bf16 GLM (#7164)#7279

Merged
ckl117 merged 1 commit intoPaddlePaddle:release/2.6from
fxyfxy777:cherry-pick/moe-permute-to-2.6
Apr 9, 2026
Merged

[Cherry-Pick][OP]Unify MoE op with moe_permute path for bf16 GLM (#7164)#7279
ckl117 merged 1 commit intoPaddlePaddle:release/2.6from
fxyfxy777:cherry-pick/moe-permute-to-2.6

Conversation

@fxyfxy777
Copy link
Copy Markdown
Contributor

💡 If this PR is a Cherry Pick, the PR title needs to follow the format by adding the [Cherry-Pick] label at the very beginning and appending the original PR ID at the end. For example, [Cherry-Pick][CI] Add check trigger and logic(#5191)

💡 如若此PR是Cherry Pick,PR标题需遵循格式,在最开始加上[Cherry-Pick]标签,以及最后面加上原PR ID,例如[Cherry-Pick][CI] Add check trigger and logic(#5191)

Motivation

使用 Paddle 官方的 moe_permute/moe_unpermute 算子替代自定义算子,简化代码并提高可维护性。

Modifications

  1. 修改 deepgemm_preprocess.cu kernel,新增 cumsum 输出
  2. 新增 FD_USE_PHI_MOE_PERMUTE 环境变量控制的代码路径
  3. 当 FD_USE_PHI_MOE_PERMUTE=1 且 quant_type=w16a16 时使用 Paddle 算子

Usage or Command

Accuracy Tests

Checklist

  • Add at least a tag in the PR title.
    • Tag list: [[FDConfig],[APIServer],[Engine], [Scheduler], [PD Disaggregation], [Executor], [Graph Optimization], [Speculative Decoding], [RL], [Models], [Quantization], [Loader], [OP], [KVCache], [DataProcessor], [BugFix], [Docs], [CI], [Optimization], [Feature], [Benchmark], [Others], [XPU], [HPU], [GCU], [DCU], [Iluvatar], [Metax]]
    • You can add new tags based on the PR content, but the semantics must be clear.
  • Format your code, run pre-commit before commit.
  • Add unit tests. Please write the reason in this PR if no unit tests.
  • Provide accuracy results.
  • If the current PR is submitting to the release branch, make sure the PR has been submitted to the develop branch, then cherry-pick it to the release branch with the [Cherry-Pick] PR tag.

@paddle-bot
Copy link
Copy Markdown

paddle-bot bot commented Apr 9, 2026

Thanks for your contribution!

Copy link
Copy Markdown

@fastdeploy-bot fastdeploy-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Code Review | 2026-04-09 17:04 CST

📋 Review 摘要

PR 概述:Cherry-pick PR #7164,使用 Paddle 官方的 moe_permute/moe_unpermute 算子替代自定义算子,简化 MoE 层代码并提高可维护性。

变更范围

  • custom_ops/gpu_ops/moe/deepgemm_preprocess.cu - 新增 cumsum 输出支持
  • fastdeploy/model_executor/layers/moe/fused_moe_cutlass_backend.py - 新增 FD_USE_PHI_MOE_PERMUTE 环境变量控制的代码路径
  • fastdeploy/model_executor/layers/moe/fused_moe_deepgemm_backend.py - 更新函数调用签名
  • tests/layers/test_fused_moe_cutlass_backend.py - 新增真实算子测试

影响面 Tag[OP] [Models]

问题

级别 文件 概述
🟡 建议 tests/layers/test_fused_moe_cutlass_backend.py:825 测试中定义了未使用的追踪变量

总体评价

PR 实现质量良好,CUDA kernel 的模板参数设计合理,Python 层与 C++ 层接口一致。新增的测试用例覆盖了 apply_tpapply_ep_prefill 两个路径,包括 noaux_tc 和非 noaux_tc 分支。发现一个小的测试代码优化点,不阻塞合入。

out = method.apply_tp(layer, x, gate)

assert permute_called["v"], "moe_permute was not called"
assert not dispatch_called["v"], "moe_expert_dispatch must not be called"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 建议 dispatch_called 变量定义后从未被更新,导致此断言始终为 True。

虽然测试通过 monkeypatchmoe_expert_dispatch 抛出 AssertionError 已经确保了该函数不会被调用(否则测试会失败),但这个断言本身是冗余的,可以移除以提高代码清晰度。

建议:

# 删除未使用的变量和断言
permute_called = {"v": False}
original_permute = paddle.nn.functional.moe_permute

# ... spy_permute 定义 ...

# 删除这行:assert not dispatch_called["v"], "moe_expert_dispatch must not be called"

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.64516% with 6 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (release/2.6@849eb3d). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...l_executor/layers/moe/fused_moe_cutlass_backend.py 79.31% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@              Coverage Diff               @@
##             release/2.6    #7279   +/-   ##
==============================================
  Coverage               ?   73.89%           
==============================================
  Files                  ?      376           
  Lines                  ?    52915           
  Branches               ?     8255           
==============================================
  Hits                   ?    39103           
  Misses                 ?    11085           
  Partials               ?     2727           
Flag Coverage Δ
GPU 73.89% <80.64%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ckl117 ckl117 merged commit dea9d35 into PaddlePaddle:release/2.6 Apr 9, 2026
33 of 37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants